-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
events: Check token and ACLs on request #19138
Conversation
This checks the request against the `read` permission for `sys/events/subscribe/{eventType}` on the initial subscribe. Future work includes moving this to its own verb (`subscribe`) and periodically rechecking the request. Tested locally by minting a token with the wrong permissions and verifying that they are rejected as expected, and that they work if the policy is adjusted to `sys/event/subscribe/*` (or the specific topic name) with `read` permissions. I had to change the `core.checkToken()` to be publicly accessible, as it seems like the easiest way to check the token on the `logical.Request` against all relevant policies, but without going into all of the complex logic further in `handleLogical()`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with some nits 👍
@@ -53,7 +63,9 @@ func TestEventsSubscribe(t *testing.T) { | |||
t.Cleanup(cancelFunc) | |||
|
|||
wsAddr := strings.Replace(addr, "http", "ws", 1) | |||
conn, _, err := websocket.Dial(ctx, wsAddr+"/v1/sys/events/subscribe/"+eventType+"?json=true", nil) | |||
conn, _, err := websocket.Dial(ctx, wsAddr+"/v1/sys/events/subscribe/"+eventType+"?json=true", &websocket.DialOptions{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also add a Dial
just above that doesn't include the token, and check that we get an error + 403 status code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
respondError(w, http.StatusUnauthorized, fmt.Errorf("permission denied or invalid token")) | ||
return | ||
} | ||
respondError(w, http.StatusInternalServerError, fmt.Errorf("error validating token")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably log the error here?
Co-authored-by: Tom Proctor <tomhjp@users.noreply.github.com>
This checks the request against the
read
permission forsys/events/subscribe/{eventType}
on the initial subscribe.Future work includes moving this to its own verb (
subscribe
) and periodically rechecking the request.Tested locally by minting a token with the wrong permissions and verifying that they are rejected as expected, and that they work if the policy is adjusted to
sys/event/subscribe/*
(or the specific topic name) withread
permissions.I had to change the
core.checkToken()
to be publicly accessible, as it seems like the easiest way to check the token on thelogical.Request
against all relevant policies, but without going into all of the complex logic further inhandleLogical()
.